
const { createWebAPIRequest } = require('../../util/util')

module.exports = [
  {
    /**
    * @api {get} /music/dj/detail [dj广播详情]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {Number} rid  rid
    */
    url: '/music/dj/detail',
    request: (req, res) => {
      const rid = req.query.rid
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const data = {
        id: rid,
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        '/weapi/djradio/get',
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  }, {
    /**
    * @api {get} /music/dj/program [dj广播 radio]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {String} asc  asc
    * @apiParam {Number} [offset=0] 页
    * @apiParam {Number} [limit=20]  每页数量
    */
    url: '/music/dj/program',
    request: (req, res) => {
      const rid = req.query.rid
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const data = {
        asc: req.query.asc,
        radioId: rid,
        limit: req.query.limit || 20,
        offset: req.query.offset || 0,
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        '/weapi/dj/program/byradio',
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  }, {
    /**
    * @api {get} /music/dj/program/detail [dj广播radio详情]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {String} asc  asc
    * @apiParam {Number} [offset=0] 页
    * @apiParam {Number} [limit=20]  每页数量
    */
    url: '/music/dj/program/detail',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const data = {
        id: req.query.id,
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        '/weapi/dj/program/detail',
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  }, {
    /**
    * @api {get} /music/dj/sub [dj广播sub]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {Number} rid
    */
    url: '/music/dj/sub',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const data = {
        id: req.query.rid,
        csrf_token: ''
      }
      const action = req.query.t === 1 ? 'sub' : 'unsub'
      createWebAPIRequest(
        'music.163.com',
        `/weapi/djradio/${action}`,
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  }, {
    /**
    * @api {get} /music/dj/catelist [dj广播分类列表]
    * @apiGroup Music
    * @apiPermission none
    */
    url: '/music/dj/catelist',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const data = {
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        '/weapi/djradio/category/get',
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  }, {
    /**
    * @api {get} /music/dj/hot [热门dj广播]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {String} type  type
    * @apiParam {Number} [offset=0] 页
    * @apiParam {Number} [limit=20]  每页数量
    */
    url: '/music/dj/hot',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const data = {
        cat: req.query.type,
        cateId: req.query.type,
        type: req.query.type,
        categoryId: req.query.type,
        category: req.query.type,
        limit: req.query.limit || 20,
        offset: req.query.offset || 0,
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        '/weapi/djradio/hot/v1',
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  }, {
    /**
    * @api {get} /music/dj/recommend [精选电台]
    * @apiGroup Music
    * @apiPermission none
    */
    url: '/music/dj/recommend',
    request: (req, res) => {
      const cookie = req.get('Cookie') || ''
      const data = {
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        '/weapi/djradio/recommend/v1',
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  }, {
    /**
    * @api {get} /music/dj/recommend/type [精选电台-分类电台]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {String} type  type
    */
    url: '/music/dj/recommend/type',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const data = {
        cateId: req.query.type,
        csrf_token: ''
      }
      createWebAPIRequest(
        'music.163.com',
        '/weapi/djradio/recommend',
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  }
]
